package njust.csc.aecore

import njust.csc.aecore.analysis.DataProcess
import njust.csc.aecore.utils.PathUtils
import njust.csc.aecore.utils.SerializeUtils
import kotlin.io.path.Path


/**
 * @Author ZhouHang
 * @Date 24/6/14 周五
 */
fun main() {
//    dataProcess (
//        "{\"absolutePath\":\"N:\\\\Code\\\\PL\\\\StaticAnalysis\\\\ApkExplorer\\\\input\\\\gamble\\\\1ace25ed992a997d43362ed4f0665e95.apk\",\"name\":\"金鼎娱乐城\",\"packageName\":\"com.cashwebappjinDingYLC\",\"size\":24523,\"versionInfo\":{\"versionCode\":1,\"versionName\":\"1.0.0\",\"minSdkVersion\":16,\"targetSdkVersion\":28,\"compileSdkVersion\":28},\"permissions\":[\"android.permission.INTERNET\",\"android.permission.ACCESS_NETWORK_STATE\",\"android.permission.WAKE_LOCK\",\"android.permission.ACCESS_WIFI_STATE\",\"com.android.vending.CHECK_LICENSE\",\"android.permission.WRITE_EXTERNAL_STORAGE\"],\"v1SignatureInfo\":{\"name\":\"CERT.RSA\",\"signatureFileName\":\"META-INF/CERT.SF\",\"certification\":{\"subject\":\"CN=1\",\"signatureType\":\"SHA256withRSA\",\"md5\":\"66 BE DA 48 2C 14 5C 9B B6 FE A4 83 83 8C 1A E0 \",\"sha1\":\"DE 57 DA 7A AC 68 9B E3 47 83 FA A0 10 9D 8C 9B 51 8D 83 74 \",\"sha256\":\"63 AA 36 63 A1 EF DD 49 80 78 41 85 C1 E7 38 15 95 64 CB FF E3 EC 05 0C FC 46 90 AE 4B CB 52 BB \"}},\"v2SignatureInfo\":{\"index\":0,\"certification\":{\"subject\":\"CN=1\",\"signatureType\":\"SHA256withRSA\",\"md5\":\"66 BE DA 48 2C 14 5C 9B B6 FE A4 83 83 8C 1A E0 \",\"sha1\":\"DE 57 DA 7A AC 68 9B E3 47 83 FA A0 10 9D 8C 9B 51 8D 83 74 \",\"sha256\":\"63 AA 36 63 A1 EF DD 49 80 78 41 85 C1 E7 38 15 95 64 CB FF E3 EC 05 0C FC 46 90 AE 4B CB 52 BB \"}},\"time\":13.977}\n"
////        "{\"absolutePath\":\"N:\\\\Code\\\\PL\\\\StaticAnalysis\\\\ApkExplorer\\\\input\\\\gamble\\\\2947767deeede2ed0975fbb40607234c.apk\",\"name\":\"福城麻将\",\"packageName\":\"com.benteng.mj\",\"size\":145951,\"versionInfo\":{\"versionCode\":110,\"versionName\":\"1.10.0\",\"minSdkVersion\":9,\"targetSdkVersion\":28},\"permissions\":[\"android.permission.READ_LOGS\",\"android.permission.READ_SMS\",\"android.permission.CALL_PHONE\",\"android.permission.FOREGROUND_SERVICE\",\"android.permission.BLUETOOTH_ADMIN\",\"android.permission.SYSTEM_ALERT_WINDOW\",\"android.permission.WRITE_EXTERNAL_STORAGE\",\"android.permission.ACCESS_FINE_LOCATION\",\"android.hardware.camera.autofocus\",\"android.permission.ACCESS_COARSE_LOCATION\",\"android.permission.ACCESS_NETWORK_STATE\",\"android.permission.WAKE_LOCK\",\"android.permission.ACCESS_WIFI_STATE\",\"android.permission.SEND_SMS\",\"android.permission.RECEIVE_SMS\",\"android.permission.WRITE_SMS\",\"android.permission.CHANGE_CONFIGURATION\",\"android.permission.ACCESS_BACKGROUND_LOCATION\",\"android.permission.GET_PACKAGE_SIZE\",\"android.permission.VIBRATE\",\"android.permission.RECORD_VIDEO\",\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\",\"android.permission.RECORD_AUDIO\",\"android.permission.REQUEST_INSTALL_PACKAGES\",\"android.permission.CHANGE_WIFI_STATE\",\"android.permission.INTERNET\",\"android.permission.GET_TASKS\",\"android.permission.CHANGE_NETWORK_STATE\",\"android.permission.CAMERA\",\"android.permission.MODIFY_AUDIO_SETTINGS\",\"android.permission.READ_EXTERNAL_STORAGE\",\"android.permission.BLUETOOTH\",\"android.permission.ACCESS_LOCATION_EXTRA_COMMANDS\",\"android.permission.READ_PHONE_STATE\",\"android.permission.WRITE_SETTINGS\"],\"v1SignatureInfo\":{\"name\":\"CERT.RSA\",\"signatureFileName\":\"META-INF/CERT.SF\",\"certification\":{\"subject\":\"CN=cui,OU=benteng,O=benteng,L=SZ,ST=GD,C=86\",\"signatureType\":\"SHA256withRSA\",\"md5\":\"B2 9B 3D 51 7F CD AE 08 2F 39 E7 2C 31 30 F2 7D \",\"sha1\":\"B2 E8 8A 8C 30 87 FE 24 26 00 C4 50 B0 BB F4 2F B0 5C 8E 10 \",\"sha256\":\"B1 8D AD 9D 96 D9 33 CB 08 85 6F 96 82 62 13 AD 1B 62 52 6D CB BF 19 47 85 CB 2F 93 88 6B 43 4A \"}},\"urls\":[\"http://pdk.payment.5playing.com/payment/WechatPayNotify\"],\"time\":13.406}\n"
//    )
    val dataProcess = DataProcess()
    val screenContent = dataProcess.parseScreencap(Path("N:\\Code\\PL\\StaticAnalysis\\ApkExplorer\\output\\userInput\\3912930c44a5170a780175dd9c63cde3"), "com.o2j66w.fgyvrr")
    println(screenContent)
}

fun dataProcess(apkInfo: String) {
    val apk = SerializeUtils.load(apkInfo)
    val dataProcess = DataProcess()
    dataProcess.parseScreencap(apk)
    dataProcess.parsePCAP(apk)
    val fullInfoPath = PathUtils.getFullInfoPath(apk.relativePath)
    SerializeUtils.dump(apk, fullInfoPath)
}
